// ----------------------------------
// RSDK Project: Sonic 2 - Boss Attack Plus
// Script Description: Attack Mode
// Script Author: Tails LP
// ----------------------------------

//-------Aliases-------//

private alias object.value0 : object.timer
private alias object.value1 : start.fadeValue
private alias object.value2 : selection.current
private alias object.value3 : arrow.offset

// menu selections


//private alias 0 : 

// object states

private alias 0 : STARTING_UP
private alias 1 : FADE_IN
private alias 2 : CHAR_SELECT
private alias 3 : MENU_IDLE
private alias 4 : BACK_TO_TITLE
private alias 5 : START_ATTACK
private alias 6 : GO_TO_RANKINGS

// selections

private alias 0 : CHARACTER_SELECT
private alias 1 : MUSIC
private alias 2 : MODE
private alias 3 : SUPER
private alias 4 : HARD
private alias 5 : ENEMY_TYPE
private alias 6 : START
private alias 7 : RANKINGS
private alias 8 : EXIT
private alias 9 : TIME_LIMIT

private alias saveRAM[493] : saved.hardMode //7B4 SData.bin
private alias saveRAM[494] : saved.bossGameMode //7B8 SData.bin
private alias saveRAM[495] : saved.bossType //7BC SData.bin
private alias saveRAM[496] : saved.BossMusic //7C0 SData.bin
private alias saveRAM[497] : saved.Character //7C4 SData.bin
private alias saveRAM[498] : saved.TimeLimit //7C8 SData.bin
private alias saveRAM[499] : saved.superMode //7CC SData.bin

private alias saveRAM[500] : bossAttackTime.SonicTails //7D0 SData.bin
private alias saveRAM[501] : bossAttackTime1.SonicTails //7D4 SData.bin
private alias saveRAM[502] : bossAttackTime2.SonicTails //7D8 SData.bin

private alias saveRAM[503] : bossAttackTime.Sonic //7DC SData.bin
private alias saveRAM[504] : bossAttackTime1.Sonic //7E0 SData.bin
private alias saveRAM[505] : bossAttackTime2.Sonic //7E4 SData.bin

private alias saveRAM[506] : bossAttackTime.Tails //7E8 SData.bin
private alias saveRAM[507] : bossAttackTime1.Tails //7EC SData.bin
private alias saveRAM[508] : bossAttackTime2.Tails //7F0 SData.bin

private alias saveRAM[509] : bossAttackTime.Knuckles //7F4 SData.bin
private alias saveRAM[510] : bossAttackTime1.Knuckles //7F8 SData.bin
private alias saveRAM[511] : bossAttackTime2.Knuckles //7FC SData.bin

private alias saveRAM[512] : bossAttackTime.KnucklesTails //800 SData.bin
private alias saveRAM[513] : bossAttackTime1.KnucklesTails //804 SData.bin
private alias saveRAM[514] : bossAttackTime2.KnucklesTails //808 SData.bin

private alias saveRAM[515] : bossAttackTime.SuperSonic //80C SData.bin
private alias saveRAM[516] : bossAttackTime1.SuperSonic //810 SData.bin
private alias saveRAM[517] : bossAttackTime2.SuperSonic //814 SData.bin

private alias saveRAM[518] : bossAttackTime.SuperTails //818SData.bin
private alias saveRAM[519] : bossAttackTime1.SuperTails //81C SData.bin
private alias saveRAM[520] : bossAttackTime2.SuperTails //820 SData.bin

private alias saveRAM[521] : bossAttackTime.SuperKnuckles //824 SData.bin
private alias saveRAM[522] : bossAttackTime1.SuperKnuckles //828 SData.bin
private alias saveRAM[523] : bossAttackTime2.SuperKnuckles //82C SData.bin

//-------Function declarations-------//

//-------Static Values-------//

//-------Tables-------//




//-------Functions-------//



event ObjectMain
	switch object.state
	case STARTING_UP
		ReadSaveRAM()
		start.fadeValue = 276
		SetScreenFade(0, 0, 0, start.fadeValue)
		object.state = FADE_IN
		break
	case FADE_IN
		if start.fadeValue > 0
			start.fadeValue -= 12
		else
			start.fadeValue = 0
			object.state = CHAR_SELECT
		endif
		SetScreenFade(0, 0, 0, start.fadeValue)
		break
	case CHAR_SELECT
		if inputPress.ButtonB == 1
			object.state = BACK_TO_TITLE
		endif
		if inputPress.ButtonA == 1
			object.state = MENU_IDLE
			selection.current = 1
			object[+3].state = 5
		endif
		break
	case MENU_IDLE
		if inputPress.down == 1
			if selection.current < 8
				selection.current ++
				if is.demoMode == 1
					if selection.current == SUPER
						selection.current ++
					endif
				endif
			else
				selection.current = 1
			endif
		endif
		if inputPress.up == 1
			if selection.current > 1
				selection.current --
				if is.demoMode == 1
					if selection.current == SUPER
						selection.current --
					endif
				endif
			else
				selection.current = 8
			endif
		endif
		if inputPress.ButtonB == 1
			object.state = CHAR_SELECT
			object[+3].state = 0
			selection.current = 0
		endif
		break
	case START_ATTACK
			SetScreenFade(0, 0, 0, start.fadeValue)
			start.fadeValue += 12
			music.volume -= 5
			if start.fadeValue >= 256
				temp4 = 0
				stage.activeList = BONUS_STAGE
				switch saved.bossGameMode
				case 0
				case 1
					stage.listPos = 0
					break
				case 2
					stage.listPos = 6
					break
				endswitch
				WritesaveRAM()
				LoadStage()
			endif
		break
	case GO_TO_RANKINGS
			SetScreenFade(0, 0, 0, start.fadeValue)
			start.fadeValue += 12
			music.volume -= 5
			if start.fadeValue >= 256
				temp4 = 0
				stage.activeList = PRESENTATION_STAGE
				stage.listPos = 1
				WritesaveRAM()
				LoadStage()
				options.bossGame = 0
			endif
		break
	case BACK_TO_TITLE
			SetScreenFade(0, 0, 0, start.fadeValue)
			start.fadeValue += 12
			music.volume -= 5
			if start.fadeValue >= 256
				temp4 = 0
				stage.activeList = PRESENTATION_STAGE
				stage.listPos = 0
				WritesaveRAM()
				LoadStage()
				options.bossGame = 0
			endif
		break
	endswitch

	switch selection.current
	case MUSIC
		if inputPress.right == 1
			if saved.BossMusic < 13
				saved.BossMusic ++
			else
				saved.BossMusic = 0
			endif
		endif
		if inputPress.left == 1
			if saved.BossMusic > 0
				saved.BossMusic --
			else
				saved.BossMusic = 13
			endif
		endif
		break
	case MODE
		if inputPress.right == 1
			if saved.bossGameMode < 2
				saved.bossGameMode ++
			else
				saved.bossGameMode = 0
			endif
		endif
		if inputPress.left == 1
			if saved.bossGameMode > 0
				saved.bossGameMode --
			else
				saved.bossGameMode = 2
			endif
		endif
		break
	case SUPER
		temp0 = inputPress.left
		temp0 |= inputPress.right
		if temp0 == 1
			if saved.superMode == 0
				saved.superMode = 1
			else
				saved.superMode = 0
			end if
		end if
		break
	case TIME_LIMIT
		temp0 = inputPress.left
		temp0 |= inputPress.right
		if temp0 == 1
			if saved.timeLimit == 0
				saved.timeLimit = 1
			else
				saved.timeLimit = 0
			end if
		end if
		break
	case HARD
		temp0 = inputPress.left
		temp0 |= inputPress.right
		if temp0 == 1
			if saved.hardMode == 0
				saved.hardMode = 1
			else
				saved.hardMode = 0
			end if
		end if
		break
	case ENEMY_TYPE
		if inputPress.right == 1
			if saved.bossType < 1
				saved.bossType ++
			else
				saved.bossType = 0
			endif
		endif
		if inputPress.left == 1
			if saved.bossType > 0
				saved.bossType --
			else
				saved.bossType = 1
			endif
		endif
		break
	case START
		temp0 = inputPress.ButtonA
		temp0 |= inputPress.ButtonC
		temp0 |= inputPress.Start
		if temp0 == 1
			object.state = START_ATTACK
			options.bossGame = 1
		endif
		break
	case RANKINGS
		if inputPress.ButtonA == 1
			object.state = GO_TO_RANKINGS
		endif
		WriteSaveRAM()
		break
	case EXIT
		if inputPress.ButtonA == 1
			object.state = BACK_TO_TITLE
		endif
		WriteSaveRAM()
		break
	endswitch
end event

event ObjectDraw

	if object.timer > 7
		object.timer = 0
		object.frame ^= 1
	else
		object.timer++
	endif
//----------------------HEADER------------------------------------

	temp1 = 16
	DrawSpriteScreenXY(0, screen.xcenter, temp1)
	temp1 += 16
	DrawSpriteScreenXY(1, screen.xcenter, temp1)

//----------------------CHARACTER SELECT--------------------------

	temp1 += 60
	temp2 = object.frame
	temp2 += 2
	if object.state == CHAR_SELECT
		DrawSpriteScreenXY(temp2, screen.xcenter, temp1)
	else
		DrawSpriteScreenXY(2, screen.xcenter, temp1)
	endif

//----------------------MUSIC-------------------------------------

	temp1 += 40
	if selection.current != 1
		DrawSpriteScreenXY(4, screen.xcenter, temp1)
	else
		DrawSpriteScreenXY(5, screen.xcenter, temp1)
	endif

	switch saved.BossMusic
	case 0
		DrawSpriteScreenFX(20, FX_INK, screen.xcenter, temp1) //S1
		break
	case 1
		DrawSpriteScreenFX(21, FX_INK, screen.xcenter, temp1) //S2
		break
	case 2
		DrawSpriteScreenFX(22, FX_INK, screen.xcenter, temp1) //S3
		break
	case 3
		DrawSpriteScreenFX(23, FX_INK, screen.xcenter, temp1) //SCD
		break
	case 4
		DrawSpriteScreenFX(24, FX_INK, screen.xcenter, temp1) //MANIA
		temp5 = screen.xcenter
		temp5 -= 24
		DrawSpriteScreenFX(31, FX_INK, temp5, temp1) 		//A
		break
	case 5
		DrawSpriteScreenFX(24, FX_INK, screen.xcenter, temp1) //MANIA
		temp5 = screen.xcenter
		temp5 -= 24
		DrawSpriteScreenFX(32, FX_INK, temp5, temp1) 		//B
		break
	case 6
		DrawSpriteScreenFX(28, FX_INK, screen.xcenter, temp1) //MANIA HBH
		break
	case 7
		DrawSpriteScreenFX(27, FX_INK, screen.xcenter, temp1) //MANIA MINI
		break
	case 8
		DrawSpriteScreenFX(25, FX_INK, screen.xcenter, temp1) //S3 MINI
		break
	case 9
		DrawSpriteScreenFX(26, FX_INK, screen.xcenter, temp1) //S&K MINI
		break
	case 10
		DrawSpriteScreenFX(29, FX_INK, screen.xcenter, temp1) //3D BLAST
		DrawSpriteScreenFX(31, FX_INK, screen.xcenter, temp1) //A
		break
	case 11
		DrawSpriteScreenFX(29, FX_INK, screen.xcenter, temp1) //3D BLAST
		DrawSpriteScreenFX(32, FX_INK, screen.xcenter, temp1) //B
		break
	case 12
		DrawSpriteScreenFX(29, FX_INK, screen.xcenter, temp1) //3D BLAST
		DrawSpriteScreenFX(33, FX_INK, screen.xcenter, temp1) //C
		break
	case 13
		DrawSpriteScreenFX(30, FX_INK, screen.xcenter, temp1) //SPINBALL
		break
	end switch

//----------------------MODE--------------------------------------

	temp1 += 12
	if selection.current != 2
		DrawSpriteScreenXY(6, screen.xcenter, temp1)
	else
		DrawSpriteScreenXY(7, screen.xcenter, temp1)
	endif

	switch saved.bossGameMode
	case 0
		DrawSpriteScreenFX(34, FX_INK, screen.xcenter, temp1) //S1+S2
		object[+5].state = 1
		object[+6].state = 1
		break
	case 1
		DrawSpriteScreenFX(20, FX_INK, screen.xcenter, temp1) //S1
		object[+5].state = 1
		object[+6].state = 0
		break
	case 2
		DrawSpriteScreenFX(21, FX_INK, screen.xcenter, temp1) //S2
		object[+5].state = 0
		object[+6].state = 1
		break
	endswitch
//----------------------SUPER-------------------------------------
if is.demoMode == 0	//removes the option for the SHC22 Demo
	temp1 += 12
	if selection.current != 3
		DrawSpriteScreenXY(8, screen.xcenter, temp1)
	else
		DrawSpriteScreenXY(9, screen.xcenter, temp1)
	endif

	if saved.superMode == 1
		DrawSpriteScreenXY(35, screen.xcenter, temp1)
	else
		DrawSpriteScreenXY(36, screen.xcenter, temp1)
	endif
endif
//----------------------HARD MODE--------------------------------

	temp1 += 12
	if selection.current != 4
		DrawSpriteScreenXY(10, screen.xcenter, temp1)
	else
		DrawSpriteScreenXY(11, screen.xcenter, temp1)
	endif

	if saved.hardMode == 1
		DrawSpriteScreenXY(35, screen.xcenter, temp1)
	else
		DrawSpriteScreenXY(36, screen.xcenter, temp1)
	endif

//----------------------ENEMY TYPE--------------------------------

	temp1 += 12
	if selection.current != 5
		DrawSpriteScreenXY(12, screen.xcenter, temp1)
	else
		DrawSpriteScreenXY(13, screen.xcenter, temp1)
	endif

	switch saved.bossType
	case 0
		arrow.offset = 48
		DrawSpriteScreenFX(37, FX_INK, screen.xcenter, temp1) //EGGMAN
		break
	case 1
		arrow.offset = 64
		DrawSpriteScreenFX(38, FX_INK, screen.xcenter, temp1) //EGG ROBO
		break
	//case 2
	//	DrawSpriteScreenFX(21, FX_INK, screen.xcenter, temp1) //METAL SONIC
	//	break
	//case 3
	//	DrawSpriteScreenFX(21, FX_INK, screen.xcenter, temp1) //KNUCKLES
	//	break
	endswitch

//----------------------START-------------------------------------
	if is.demoMode == 1	//the section stays in place after disableing Super
		temp1 += 32
	else
		temp1 += 20
	endif
	if selection.current != 6
		DrawSpriteScreenXY(14, screen.xcenter, temp1)
	else
		DrawSpriteScreenXY(15, screen.xcenter, temp1)
	endif

//----------------------RANKINGS----------------------------------

	temp1 += 12
	if selection.current != 7
		DrawSpriteScreenXY(16, screen.xcenter, temp1)
	else
		DrawSpriteScreenXY(17, screen.xcenter, temp1)
	endif

//----------------------EXIT--------------------------------------

	temp1 += 12
	if selection.current != 8
		DrawSpriteScreenXY(18, screen.xcenter, temp1)
	else
		DrawSpriteScreenXY(19, screen.xcenter, temp1)
	endif

//----------------------ARROWS------------------------------------


	switch selection.current
	case MUSIC	
		switch saved.BossMusic
		case 0
		case 1
		case 2
		case 3
			arrow.offset = 16
			break
		case 4
		case 5
		case 8
		case 9
			arrow.offset = 56
			break
		case 6
			arrow.offset = 72
			break
		case 7
		case 10
		case 11
		case 12
			arrow.offset = 80
			break
		case 13
			arrow.offset = 64
			break
		endswitch
		break
	case MODE
		switch saved.bossGameMode
		case 0
			arrow.offset = 44
			break
		case 1
		case 2
			arrow.offset = 16
			break
		endswitch	
		break
	case TIME_LIMIT
		if saved.timeLimit == 1
			arrow.offset = 16
		else
			arrow.offset = 24
		endif
		break
	case HARD
		if saved.hardMode == 1
			arrow.offset = 16
		else
			arrow.offset = 24
		endif
		break
	case SUPER
		if saved.superMode == 1
			arrow.offset = 16
		else
			arrow.offset = 24
		endif
		break
	case ENEMY_TYPE	
		switch saved.bossType
		case 0
			arrow.offset = 48
			break
		case 1
			arrow.offset = 64
			break
		endswitch
		break
	endswitch

	if selection.current >= 1
		if selection.current <= 5
			temp6 = selection.current
			if is.demoMode == 1	//removes Super option for the SHC22 Demo
				if selection.current > 2
					temp6 -= 1
				endif
			endif
			temp6 *= 12
			temp6 += 120
			temp2 = object.frame
			temp2 += 39
			DrawSpriteScreenXY(temp2, screen.xcenter, temp6)
			temp2 += 2
			temp1 = screen.xcenter
			temp1 += arrow.offset
			temp1 += 8
			DrawSpriteScreenXY(temp2, temp1, temp6)
		endif
	endif


end event

event ObjectStartup
	ReadSaveRAM()
	tileLayer[1].scrollPos = 0xa00000
	if stage.listPos == 3
		Stage[0].ActiveLayer=1
		SetMusicTrack("DeathEgg.ogg", 0, 1)
	endif
	PlayMusic(0)

	LoadSpriteSheet("LevelSelect/Icons.gif")
	SpriteFrame(-48, -7, 96, 14, 226, 151)			//00 ATTACK HEADER
	SpriteFrame(-32, -7, 64, 14, 185, 109)			//01 MODE HEADER

	SpriteFrame(-32, -32, 64, 64, 98, 249)			//02 Char Select Frame Yellow
	SpriteFrame(-32, -32, 64, 64, 163, 249)			//03 Char Select Frame Red

	SpriteFrame(-90, -3, 40, 7, 103, 438)			//04 MUSIC
	SpriteFrame(-90, -3, 40, 7, 103, 446)			//05 MUSIC Yellow

	SpriteFrame(-82, -3, 32, 7, 249, 494)			//06 MODE
	SpriteFrame(-82, -3, 32, 7, 216, 494)			//07 MODE Yellow

	SpriteFrame(-90, -3, 40, 7, 240, 398)			//08 SUPER
	SpriteFrame(-90, -3, 40, 7, 305, 382)			//09 SUPER Yellow

	SpriteFrame(-122, -3, 72, 7, 289, 350)			//10 HARD MODE
	SpriteFrame(-122, -3, 72, 7, 289, 358)			//11 HARD MODE Yellow

	SpriteFrame(-130, -3, 80, 7, 256, 438)			//12 ENEMY TYPE
	SpriteFrame(-130, -3, 80, 7, 256, 446)			//13 ENEMY TYPE Yellow

	SpriteFrame(-20, -3, 40, 7, 256, 454)			//18 START
	SpriteFrame(-20, -3, 40, 7, 256, 462)			//19 START Yellow

	SpriteFrame(-32, -3, 64, 7, 240, 382)			//16 RANKING
	SpriteFrame(-32, -3, 64, 7, 265, 390)			//17 RANKING Yellow

	SpriteFrame(-16, -3, 32, 7, 256, 358)			//18 EXIT
	SpriteFrame(-16, -3, 32, 7, 256, 350)			//19 EXIT Yellow


	SpriteFrame(50, -3, 16, 7, 83, 414)			//20 S1
	SpriteFrame(50, -3, 16, 7, 83, 422)			//21 S2
	SpriteFrame(50, -3, 16, 7, 83, 430)			//22 S3
	SpriteFrame(50, -3, 16, 7, 83, 446)			//23 SCD
	SpriteFrame(50, -3, 40, 7, 224, 470)			//24 MANIA
	SpriteFrame(50, -3, 56, 7, 83, 454)			//25 S3 MINI
	SpriteFrame(50, -3, 56, 7, 83, 462)			//26 S&K MINI
	SpriteFrame(50, -3, 80, 7, 216, 478)			//27 MANIA MINI
	SpriteFrame(50, -3, 72, 7, 1, 501)			//28 MANIA HBH
	SpriteFrame(50, -3, 64, 7, 265, 470)			//29 3D BLAST
	SpriteFrame(50, -3, 64, 7, 248, 486)			//30 SPINBALL

	SpriteFrame(122, -3, 8, 7, 34, 477)			//31 A
	SpriteFrame(122, -3, 8, 7, 43, 477)			//32 B
	SpriteFrame(122, -3, 8, 7, 52, 477)			//33 C

	SpriteFrame(50, -3, 44, 7, 34, 453)			//34 S1&S2

	SpriteFrame(50, -3, 16, 7, 216, 398)			//35 ON
	SpriteFrame(50, -3, 24, 7, 208, 406)			//36 OFF

	SpriteFrame(50, -3, 48, 7, 281, 398)			//37 EGGMAN
	SpriteFrame(50, -3, 64, 7, 281, 406)			//38 EGG ROBO

	SpriteFrame(44, -2, 4, 5, 87, 293)			//39 Arrow Left
	SpriteFrame(0, 0, 0, 0, 0, 0)				//40 Arrow Left Blank
	SpriteFrame(44, -2, 4, 5, 92, 293)			//41 Arrow Right
	SpriteFrame(0, 0, 0, 0, 0, 0)				//42 Arrow Left Blank

end event

event RSDKDraw
    DrawSprite(0)
end event

event RSDKLoad
    LoadSpriteSheet("Global/Display.gif")
    SpriteFrame(-16, -16, 32, 32, 223, 172)
end event